<template>
<q-layout view="hHh Lpr fFf">
    <!-- Be sure to play with the Layout demo on docs -->

    <!-- (Optional) The Header -->
    <q-header reveal :class="isShow?'back-dark shadow-7':'transparent'">
        <q-toolbar class="transparent " style="width: 100%; height: 50px">
            <q-btn @click="handleBack" falt round icon="mdi-keyboard-backspace"></q-btn>
            <q-img v-if="isShow" src="icons/一方映画logo200708竖版亮色.png" :width="$q.platform.is.mobile ? '150px' : '200px'" contain />

            <q-space></q-space>
            <q-bar dark style="height: 60px" class="transparent">

                <q-space />

                <q-btn flat dense @click="handleMinWin" :class="isShow?'':'shadow-7'" icon="mdi-minus" class="items-center">

                    <q-tooltip>窗口还原(Esc)</q-tooltip>
                </q-btn>
                <q-btn flat dense :class="isShow?'':'shadow-7'" icon="crop_square" @click="handleMaxWin">
                    <q-tooltip>窗口最大化</q-tooltip>
                </q-btn>
                <q-btn flat dense :class="isShow?'':'shadow-7'" icon="mdi-format-list-bulleted" @click="leftDrawer = !leftDrawer" />
                <!-- <q-btn dense flat icon="close"><q-tooltip>关闭项目</q-tooltip></q-btn> -->
            </q-bar>
            <!-- <q-btn flat round dense icon="menu" class="mobile-only q-mr-sm" /> -->
        </q-toolbar>
    </q-header>

    <!-- (Optional) The Footer -->
    <q-footer v-model="isShow" class="row back-dark items-center" style="height:40px">
        <q-btn flat round size="15px" dense icon="list" @click="leftDrawer = !leftDrawer" />

    </q-footer>

    <!-- (Optional) A Drawer; you can add one more with side="right" or change this one's side -->
    <q-drawer v-model="leftDrawer" :overlay="isShow" :width="300" :breakpoint="100" side="left" class="shadow-7" content-class="bg-grey-10" :behavior="!$platform.inDesktop()?'mobile':'default'">
        <!-- QScrollArea is optional -->
        <q-scroll-area style="height: calc(100% - 80px); margin-top: 80px" class="q-px-md ">
            <q-card class="back-dark q-my-sm" v-for="item,index in recceList" :key="index">
                <q-card-section>
                    {{item.name}}
                </q-card-section>
                <!-- <q-img :src="GLOBAL.serverurl + item.url">

          </q-img> -->
                <q-separator color="grey-7" class="q-my-sm" inset></q-separator>
                <q-card-section class="q-py-sm row justify-end">
                    <q-btn outline @click="loadRecce(item)">加载</q-btn>
                </q-card-section>

            </q-card>

        </q-scroll-area>
        <q-card flat class="absolute-top transparent q-py-sm q-px-md q-mt-md" style="height: 80px">
            <div class="bg-transparent row justify-between">
                <div class="text-weight-bold text-h6">堪景列表
                    <q-btn flat round size="15px" dense icon="list" @click="leftDrawer = !leftDrawer" />
                </div>
                <q-btn dense color="primary" outline icon="upload" @click="handleUploadDialog">上传</q-btn>
            </div>
            <q-separator color="grey-7" class="q-my-md"></q-separator>
        </q-card>

    </q-drawer>
    <q-dialog v-model="isUploadDialog" persistent>
        <q-card class="bg-dark q-pa-none">
            <q-card-section class="row items-center q-pa-none">
                <div class="column">

                    <!-- <q-uploader
                  dark
                  url="http://localhost:4444/upload"
                  label="上传"
                  multiple
                  :headers="uploadheaders"
                  :form-fields="formfields"

                >
                      <i class="el-icon-upload"></i>
                      <div class="el-upload__text">
                          将文件拖到此处，或<em>点击上传</em>
                      </div>
                      <div class="el-upload__tip" slot="tip">
                          上传文件类型：jpg文件
                      </div>
                  </q-uploader> -->
                </div>
            </q-card-section>

            <q-card-actions align="right">
                <!-- <q-btn outline label="上传文件" color="primary" @click="submitUpload" />
              <q-btn outline label="取消" color="primary" v-close-popup /> -->
            </q-card-actions>
        </q-card>
    </q-dialog>

    <q-page-container @click="leftDrawer =false">

        <!-- This is where pages get injected -->
        <router-view ref="recceContainer" :user="user" :isShow="isShow" />
    </q-page-container>

</q-layout>
</template>

<script>
import {
    loadRecceList
} from "assets/api/studio/recce"
export default {
    props: {
        user: {
            type: Object
        }
    },
    data() {
        return {
            leftDrawer: true,
            pid: '',
            isUploadDialog: false,
            uploadheaders: {},
            recceList: [],
            isFull: false,
            isShow: true,
        }
    },
    created() {
        this.pid = this.$route.params.pid;
        // let user = this.$storage.getItem("user");
        //     this.uploadheaders = {
        //         name: "Authorization",
        //         value: user.token,
        //     };
        //     this.formfields.push({
        //         name: "pid",
        //         value: this.pid,
        //     });
        this.handleLoadRecceList()
    },
    mounted() {
        this.$emit('isSingle', true)
        this.i_name = setInterval(() => {
          this.projectInfo = this.$store.state.projectinfo;

            if (this.projectInfo.name) {
                document.title = this.projectInfo.name + '--预演系统';
                clearInterval(this.i_name)
            }

        }, 500);
    },
    watch: {
        '$q.fullscreen.isActive'(val) {
            if (val) {
                this.isShow = false;
            } else {
                this.isShow = true;
            }

            console.log(val ? 'In fullscreen now' : 'Exited fullscreen')
        }
    },
    beforeDestroy() {
        this.$emit('isSingle', false)
    },
    methods: {
        handleLoadRecceList() {

            loadRecceList({
                pid: this.pid
            }).then(res => {
                console.log(res);
                if (res.data.code == 1) {

                    this.recceList = res.data.data
                }
            })
        },
        handleBack() {
            this.$router.replace('/studio/' + this.pid)
        },
        loadRecce(item) {
            console.log(this.$refs.recceContainer, item);
            let serverurl = this.GLOBAL.serveurl;
            this.$refs.recceContainer.loadSceneBg(serverurl + item.url)
        },
        handleMinWin() {
            this.isShow = false;
            this.$refs.recceContainer.onWindowResize();
            this.$q.fullscreen
                .exit()
                .then(() => {
                    // v1.5.0+
                    // success!
                })
                .catch((err) => {
                    // v1.5.0+
                    // oh, no!!!
                });
        },
        handleMaxWin() {
            this.isShow = false;
            this.$refs.recceContainer.onWindowResize();
            this.$q.fullscreen
                .request()
                .then(() => {
                    console.log(this.$refs);
                })
                .catch((err) => {
                    // v1.5.0+
                    // oh, no!!!
                });
        },
        handleUploadDialog() {
            this.isUploadDialog = true;
        }

    }
}
</script>
